package com.example.springboot.topic;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: 12-springboot-rabbitmq
 * @description: MsgSender
 * @author: Yuwl
 * @create: 2019-12-27 17:25
 **/
@Component
public class MsgSender {

	@Autowired
	private AmqpTemplate amqpTemplate;

	/**
	 * send1方法会匹配到topic.#和topic.message，两个Receiver都可以收到消息
	 */
	public void send1(int n) {
		String context = "hi, i am message " + n;
		System.out.println("Sender : " + context);
		this.amqpTemplate.convertAndSend("mybootexchange", "topic.message", context);
	}

	/**
	 * send2只有topic.#可以匹配所有只有Receiver2监听到消息
	 */
	public void send2(int n) {
		String context = "hi, i am message " + n;
		System.out.println("Sender : " + context);
		this.amqpTemplate.convertAndSend("mybootexchange", "topic.messages", context);
	}
}
